package team2.arsystem.GUI;

import java.util.Date;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.DatePicker;
import android.widget.EditText;

public class AddToDebitAccount extends Activity{

	private String debitTxDescription = "";
	private double debitTxAmount = 0.0;
	private boolean divideAmongMembers = false;
	public static Date transactionDate = new Date();
	public static Date reminderDate = new Date();
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);
		setContentView(R.layout.addtodebitpart1);
		
		 Button continueButton = (Button)findViewById(R.id.buttonContinueAddDebit);
		 final EditText debitDescEditText = (EditText)findViewById(R.id.editTextDebitDescription);
	     final EditText debitAmountEditText = (EditText)findViewById(R.id.editTextDebitAmount);
		 final CheckBox divideDebitAmount = (CheckBox)findViewById(R.id.checkBoxDivideDebitAmount);
	     final DatePicker debitTxDate = (DatePicker)findViewById(R.id.datePickerDebitTxDate);
	     final DatePicker debitReminderDate = (DatePicker)findViewById(R.id.DatePickerDebitReminderDate);
	     Button cancelButton = (Button)findViewById(R.id.buttonCancelAddToDebit);
	     
	     /* If Continue button is clicked , put the required information in next Intent and start the Intent for the second screen for this use case.*/
		 continueButton.setOnClickListener(new OnClickListener() {
				
	        	public void onClick(View v) {
	        
	        		try
	        		{
	        		
	        		 debitTxDescription = 	debitDescEditText.getText().toString();
	        		 debitTxAmount = Double.parseDouble(debitAmountEditText.getText().toString());
	        		 divideAmongMembers = 	divideDebitAmount.isChecked();
	        		 transactionDate = new Date(debitTxDate.getYear(), debitTxDate.getMonth()+1,debitTxDate.getDayOfMonth());
	        		 reminderDate = new Date(debitReminderDate.getYear(), debitReminderDate.getMonth()+1,debitReminderDate.getDayOfMonth());
	        		 
	        		 Class debitScreen2 = Class.forName("team2.arsystem.GUI."+"AddToDebitScreen2");
	        		 Intent myIntent = new Intent(AddToDebitAccount.this,debitScreen2);
	        		 myIntent.putExtra("team2.arsystem.GUI.AddTODebitScreen.amount",debitTxAmount);
	        		 myIntent.putExtra("team2.arsystem.GUI.AddTODebitScreen.txDesc",debitTxDescription);
	        		 myIntent.putExtra("team2.arsystem.GUI.AddTODebitScreen.divideAmongMembers",divideAmongMembers);
	        		        		 
	        		 startActivity(myIntent);
	        		}
	        		 catch(Exception e)
	        		 {
	        			 e.printStackTrace();
	        		 }
	        	
	        	}
		 });
		 
		 /* If Cancel button is clicked, take the user to the menu screen*/
		 cancelButton.setOnClickListener(new OnClickListener() {
				
	        public void onClick(View v) {
	        		
	          try
	          {
	           	 Class menuScreen = Class.forName("team2.arsystem.GUI."+"DebitMenuScreen");
	          	 Intent myIntent = new Intent(AddToDebitAccount.this,menuScreen);
	          	 startActivity(myIntent);
	       	  }
	                   
	          catch(Exception e)
	          {
	              e.printStackTrace();
	          }
	                    		 
	       }
	        	
	     });
	        
	}
	
	}


